Putting multiple statements on a single line lowers the code readability and makes debugging the code more complex.
if someCondition { doSomething() } // Noncompliant
var result = doSomething(); return result // Noncompliant
Write one statement per line to improve readability.
if someCondition {
doSomething()
}
var result = doSomething()
return result
Exceptions
The rule ignores:
- variable declarations initialized with a code block
var x : Int { return 0 } // Compliant by exception
- closure expressions containing a single statement
doSomething({ (x: Int, y: Int) -> Bool in return x > y }, 5) // Compliant by exception